<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>websocketDemo</title>
</head>
<body>
<button id="connect">连接服务端</button>
<button id="send">发送数据给服务端</button>
<div>
    <h2>接收的数据</h2><br>
    <div id="recv"></div>
</div>
<script>
    var connect = document.querySelector("#connect")
    var send = document.querySelector("#send")
    var recv = document.querySelector("#recv")
    let WS = null
    connect.onclick = function(){
      WS= new WebSocket('ws://localhost:9998')
      WS.onopen = () =>{
        send.disanled = true
      }
      WS.onmessage = msg => {
        console.log(msg)
        recv.innerHTML= JSON.stringify(msg)
      }
      WS.onclose = () =>{
        console.log(连接失败/断开连接)
      }
    }
    send.onclick = function(){
      WS.send(JSON.stringify(
        {
            action:'fullScreen',
            socketType:'fullScreen',
            chartName:'trend',
            value:true
            }
        )
      )
    }
</script>
</body>
</html>
